package com.example.androidproject.novel.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.androidproject.novel.bean.NovelBean;
import com.example.androidproject.R;

import java.util.ArrayList;

public class RecommendContentAdapter extends BaseAdapter {
    private final Context mContext;
    private final ArrayList<NovelBean.DataBean> data;

    public RecommendContentAdapter(Context mContext, ArrayList<NovelBean.DataBean> data) {
        this.mContext = mContext;
        this.data = data;
    }

    @Override
    public int getCount() {
        if (data == null) return 0;
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.recomment_body_item, null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = convertView.findViewById(R.id.iv_body);
            viewHolder.textView = convertView.findViewById(R.id.tv_body);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(data.get(position).getImage()).into(viewHolder.imageView);
        viewHolder.textView.setText(data.get(position).getTitle());
        return convertView;
    }

    class ViewHolder {
        TextView textView;
        ImageView imageView;
    }

}
